package com.qms.repast.ui.presenter;

import android.app.Activity;

import com.google.gson.Gson;
import com.orhanobut.logger.Logger;
import com.qms.repast.commons.Constants;
import com.qms.repast.entity.reqbean.ReqDishesInfo;
import com.qms.repast.entity.resbean.DishesInfo;
import com.qms.repast.module.UserModule;
import com.qms.repast.ui.base.BasePresenter;
import com.qms.repast.ui.view.ICuisineInfoView;

import io.reactivex.observers.DisposableObserver;

/**
 * @author 泅渡者
 * @date 2018/9/20 0020
 * @describe:
 */
public class CuisineInfoPresenter extends BasePresenter<ICuisineInfoView> {
	private UserModule userModule;

	public CuisineInfoPresenter (Activity mContext, ICuisineInfoView mView) {
		super(mContext, mView);
		userModule = new UserModule(mContext);
	}

	/**
	 * 获取菜品详情
	 *
	 * @param reqDishesInfo
	 */
	public void getDishInfo (ReqDishesInfo reqDishesInfo) {
		userModule.reqDishInfo(reqDishesInfo, new DisposableObserver<DishesInfo>() {
			@Override
			public void onError (Throwable throwable) {
				Logger.e(throwable.getMessage());
			}

			@Override
			public void onComplete () {
				Logger.d("Request is End");
			}

			@Override
			public void onNext (DishesInfo dishesInfo) {
				Logger.json(new Gson().toJson(dishesInfo));
				if (Constants.SUCCESS == dishesInfo.getCode()) {
					mView.updateUI(dishesInfo);
				}

			}
		});
	}
}
